
import 'package:flutter/material.dart';
import 'package:furaha_mkopo/commonTool/fm_jump_tool.dart';
import 'package:furaha_mkopo/manager/fm_init_manager.dart';
import 'package:get/get.dart';

class FMTabController extends GetxController with GetSingleTickerProviderStateMixin{

  TabController? tabController;

  List<String> tabMenus = ["Home","Me"];

  int selectIndex = 0;

  @override
  void onInit() {
    super.onInit();
    tabController = TabController(length: tabMenus.length, vsync: this);

    tabController?.addListener(_handleTabIndexChangeTick);
  }

  void _handleTabIndexChangeTick() {
    if (tabController?.index.toDouble() == tabController?.animation!.value) {
      selectIndex = tabController!.index;
      update();
    }
  }

  void onItemTapped(int index) {
    if (index == 1 && !FMInitManager().isLogin) {
      FMJumpTool.jumpLogin();
      return;
    }

    selectIndex = index;
    tabController?.index = index;
    update();
  }

  void jumpHome() {
    tabController?.index = 0;
  }
}